import qs from 'qs';
import {
    kmodel
} from '../api';
let Slist = [],
    SMore;
export default {
    namespace: 'kmodel',
    state: {
        userMsg: {
            id: null,
            loginAccount: null,
            location: null
        },
        data: [],
        expressData: [],
        kData: {},
        SList: [],
        msglist:[],
        uAdressData: {},
        SMore: false
    },
    reducers: {
        queryListSuccess(state, {
            payload
        }) {
            return {
                ...state,
                ...payload
            };
        }
    },
    effects: {
        * msgserch({
            payload: params
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(mmodel.msgquery, params);
            // console.log(jsonResult.data)
            yield put({
                type: 'serchSuccess',
                payload: {
                    msglist: jsonResult.data
                }
            });
        },
        * saveStatus({
            payload: params
        }, {
            call,
            put
        }) {
            // console.log(params)
            yield put({
                type: 'queryListSuccess',
                payload: {
                    urData: params
                }
            });
        },
        * saveDetail({
            payload: params
        }, {
            call,
            put
        }) {
            // console.log(params)
            yield put({
                type: 'queryListSuccess',
                payload: {
                    uAdressData: params
                }
            });
        },

        * saveVideoStatus({
            payload: params
        }, {
            call,
            put
        }) {
            // console.log(params)
            yield put({
                type: 'queryListSuccess',
                payload: {
                    videoData: params
                }
            });
        },
        * queryExpressCode({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.queryExpressCode, params);
            yield put({
                type: 'serchSuccess',
                payload: {
                    expressData: jsonResult.data
                }
            });
            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * queryExpress({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.queryExpress, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * getExpressCom({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.getExpressCom, params);

            if (typeof func === 'function') {
                func(jsonResult);
            }
        },
        * qiniuToken({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.qiniuToken, params);

            if (typeof func === 'function') {
                func(jsonResult);
            }
        },
        
        * getExpressCom({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.getExpressCom, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * getExpressRefuse({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.getExpressRefuse, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * queryUpdate({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.update, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * confirm({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.confirm, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * getWechatConfig({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.getWechatConfig, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * expressindex({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.expressindex, params);
            if (jsonResult.data != '[]') {
                if (params.page == 1) {
                    Slist = [];
                }
                // Stotal=jsonResult.data.total;
                // console.log(params)
                if (jsonResult.data && jsonResult.data.list != null && jsonResult.data.list.length > 0) {
                    SMore = true;
                    for (var i = 0; i < jsonResult.data.list.length; i++) {
                        Slist.push(jsonResult.data.list[i]);
                    }
                } else {
                    if (params.page == 1) {
                        Slist = [];
                        SMore = false;
                    }

                }

            } else {
                Slist = [];
                SMore = false;
                // Stotal:0;
            }
            // if (typeof func === 'function') {
            //     func(jsonResult.data);
            // }
            yield put({
                type: 'queryListSuccess',
                payload: {
                    Slist: Slist,
                    SMore: SMore
                }
            });
        },
        * comment({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.comment, params);

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },
        * e_bikeInfo({
            payload: {
                params,
                func
            }
        }, {
            call,
            put
        }) {
            const {
                jsonResult
            } = yield call(kmodel.e_bikeInfo, params);
            // console.log(jsonResult.data)
            yield put({
                type: 'queryListSuccess',
                payload: {
                    kData: jsonResult.data
                }
            });

            if (typeof func === 'function') {
                func(jsonResult.data);
            }
        },

    }
};